home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Textension.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
-
- #ifndef _Textension_
- #define _Textension_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _StyledText_
- #include "StyledText.h"
- #endif
-
- #ifndef _Display_
- #include "Display.h"
- #endif
-
- #ifndef _Selection_
- #include "Selection.h"
- #endif
-
- #ifndef _RunObject_
- #include "RunObject.h"
- #endif
-
- #ifndef _RunsRanges_
- #include "RunsRanges.h"
- #endif
-
- #ifdef txtnRulers
- #ifndef _RulerObject_
- #include "RulerObject.h"
- #endif
-
- #ifndef _RulersRanges_
- #include "RulersRanges.h"
- #endif
- #endif
-
- #ifndef _Frames_
- #include "Frames.h"
- #endif
-
- #ifndef _FrameFormatter_
- #include "FrameFormatter.h"
- #endif
-
- #ifndef _Formatter_
- #include "Formatter.h"
- #endif
-
- #ifndef _TextensionIOSuite_
- #include "TextensionIOSuite.h"
- #endif
-
- //***************************************************************************************************
-
-
- //"KeyDown" result
- typedef ushort TKeyDownFlags;
-
- const TKeyDownFlags kNoKeyDownFlags = 0;
- const TKeyDownFlags kKeyDownKnown = 1 << 0;
- const TKeyDownFlags kTextensionModif = 1 << 1;
- const TKeyDownFlags kContinuousObjectsModif = 1 << 2; //continuous run and/or ruler changes (for setup menus)
- const TKeyDownFlags kArrowKey = 1 << 3;
- //••flags 1 << 4 through 1 << 10 are reserved
- //***************************************************************************************************
-
- //flags input to "CharsChanged"
- typedef uchar TCharsChangedFlags;
-
- const TCharsChangedFlags kCalcRuns = 1;
-
- #ifdef txtnRulers
- const TCharsChangedFlags kCalcRulers = 2;
- #endif
-
- const TCharsChangedFlags kCalcLines = 4;
-
- #ifdef txtnRulers
- const TCharsChangedFlags kCalcAll = kCalcRuns + kCalcRulers + kCalcLines;
- #else
- const TCharsChangedFlags kCalcAll = kCalcRuns + kCalcLines;
- #endif
-
- const TCharsChangedFlags kNoCalc = 0;
-
- //***************************************************************************************************
-
- const short kKeyDownBufferSize = 50;
-
- struct TKeyDownParams {
- TOffsetRange range2Replace;
-
- long countSelectedChars;
-
- short countNewChars;
-
- uchar newChars[kKeyDownBufferSize];
-
- TKeyDownFlags flags;
- };
- //***************************************************************************************************
-
- struct TTextensionHandlers {
- TTextensionHandlers();
-
- CTextensionDisplay* displayHandler;
-
- CFrames* framesHandler; //if nil ==> CMonoFrame is created
-
- CSelection* selectionHandler;
-
- CFormatter* formatHandler;
- };
- //****************************************************
-
- #ifdef txtnNever
- struct TTextensionContext {
- CArray* charsHandler;
-
- CRunsRanges* runsRanges;
-
- #ifdef txtnRulers
- CRulersRanges* rulersRanges;
- #endif
-
- CTextensionDisplay* displayHandler;
-
- CSelection* selectionHandler;
-
- CFormatter* formatterHandler;
- CFrameFormatter* frameFormatterHandler;
- };
- //****************************************************
- #endif
-
- struct TTextDescriptor {
- TTextDescriptor() {
- fTextStream = nil;
- fTextPtr = nil;
- fTextSize = 0;
- }
-
- TTextDescriptor(CStream* stream) {
- fTextStream = stream;
- fTextSize = stream->GetSize();
- fTextPtr = nil;
- }
-
- TTextDescriptor(uchar* textPtr, long textSize) {
- fTextPtr = textPtr;
- fTextSize = textSize;
- fTextStream = nil;
- }
-
- CStream* fTextStream;
- uchar* fTextPtr;
- long fTextSize;
- };
-
- struct TReplaceParams {
- TReplaceParams(); //initialized to nils
-
- TReplaceParams(const TTextDescriptor& textDesc
- , Boolean calcScriptRuns = true, Boolean usePendingRun = true);
-
- TReplaceParams(const TTextDescriptor& textDesc, CObjectsRanges* runs, Boolean plugNewRuns);
-
- TReplaceParams(const TTextDescriptor& textDesc, CRunObject* replaceObj, Boolean takeObjCopy);
-
- TReplaceParams(CTextensionIOSuite* ioSuite);
-
- TReplaceParams(CRunObject* runObj, Boolean takeObjCopy = false);
- //non text run obj (pict, sound, ..)
-
- TTextDescriptor fTextDesc;
-
- Boolean fCalcScriptRuns;
- Boolean fUsePendingRun;
-
- CTextensionIOSuite* fIOSuite;
-
- CObjectsRanges* fNewRuns;
- Boolean fPlugNewRuns;
-
- CRunObject* fReplaceObj;
- Boolean fTakeObjCopy;
-
- Boolean fTrailEdge;
- };
- //****************************************************
-
- class CTextension : public CStyledText {
-
- friend class CSelection;
-
- public:
- //--------
- static OSErr TextensionStart(CTextensionScrap* localScrap = nil);
- static void TextensionTerminate();
-
- /*next 2 should be called after TextensionInit.
- the first run obj to RegisterIORun should be the text one
- */
- static void RegisterIORun(CRunObject* theObject);
-
- #ifdef txtnRulers
- static void RegisterIORuler(CRulerObject* theObject);
- #endif
-
- static CRunObject* GetNewRunObject(); //••should be called after calling the first RegisterIORun
-
- static CRunObject* GetDefaultRun() {return fDefaultRun;}
- inline static void SetDefaultRun(CRunObject* defRun) {fDefaultRun = defRun;}
-
- inline static CTextensionScrap* GetLocalScrap()
- {return fLocalScrap;}
-
- inline static void SetImaging(Boolean on_off) {gTextensionImaging = on_off;}
- inline static Boolean IsImaging() {return gTextensionImaging;}
-
- CTextension();
-
- OSErr ITextension(GrafPtr textPort, TTextensionHandlers* handlers, TSize sizeInfo = kLargeSize);
- virtual void Free();
-
- //•handlers
- inline CSelection* GetSelectionHandler() {return fSelection;}
-
- #ifdef txtnRulers
- inline CRulersRanges* GetRulersRanges() {return fRulersRanges;}
- #endif
-
- inline CFrames* GetFramesHandler() {return fDisplay->GetFramesHandler();}
- inline CFormatter* GetFormatter() {return fFormatter;}
- inline CFrameFormatter* GetFrameFormatter() {return fFrameFormatter;}
-
- //•Frames
- virtual short DisplayChanged(const CDisplayChanges* displayChanges);
- /*
- •Focus should be made before calling this routine (it may needs to draw).
-
- call it after calling any "Frames" member which returns a "CDisplayChanges".
- After calling "DisplayChanged", caller should test the returned result for the following values:
- -kRedrawAll ==> redraw the whole content of the fFrames.
- -kCheckSize ==> adjust the frames's size.
- -kCheckUpdate ==> some frames has been invalidated, process the update event for fast response.
- */
-
- //•Drawing
- inline void GetViewRect(Rect* theRect) const {fDisplay->GetViewRect(theRect);}
- inline void SetViewRect(const Rect* theRect) {fDisplay->SetViewRect(theRect);}
-
- inline void HideDrawPen() {fDisplay->HideDrawPen();}
- inline void ShowDrawPen() {fDisplay->ShowDrawPen();}
- inline void HideSelectionPen() {fSelection->DisableDrawing();}
- inline void ShowSelectionPen() {fSelection->EnableDrawing();}
-
- virtual void Draw(const Rect *updateRect, TDrawFlags drawFlags = kEraseBeforeDraw);
-
-
- //•Editing
- virtual void CalcKeyDownParams(const EventRecord* event, Boolean bufferKeys, TKeyDownParams* params);
- TKeyDownFlags KeyDown(const EventRecord* event, TKeyDownParams* params = nil);
-
- OSErr Cut();
- OSErr Copy();
-
- inline static Boolean CanPaste() {return fLocalScrap->CanPaste();}
-
- OSErr Paste();
- void Clear();
-
- inline short GetLastEditAction() {return fDisplay->GetLastEditAction();}
-
-
- //•Formatting
- inline void DisableFormatting() {fFormatter->DisableFormatting();}
- inline void EnableFormatting() {fFormatter->EnableFormatting();}
- virtual OSErr Format(Boolean temporary = false, long firstChar =-1, long count =-1);
- /*does not redraw (unless firstChar and count > 0)
- if "temporary" is true ==> assumed that Format will be called again to restore the old lines ends,
- this is useful for non wysiwyg printing.
- "temporary" can be true only if format all (firstChar < 0)
- */
-
- //•Scrolling
- void SetAutoScroll(Boolean flag) {fSelection->SetAutoScroll(flag);} //false by default
- inline void Scroll(const LongPoint* scrollVals) {fDisplay->Scroll(scrollVals);}
- inline void GetScrolledValues(LongPoint* scrolledVals) {fDisplay->GetScrolledValues(scrolledVals);}
-
- //•Selection
- virtual void Activate(Boolean activ, Boolean turnSelOn =true);
-
- inline void GetSelectionRange(TOffsetRange* selRange) const {fSelection->GetSelectionRange(selRange);}
-
- virtual void SetSelectionRange(const TOffsetRange& selRange
- , Boolean forceOn = true, Boolean updateKeyScript=true);
- void Idle();
- inline unsigned long GetIdleTime() {return fSelection->GetIdleTime();}
- //Idle should be called after the returned value (in Ticks)
-
- virtual Boolean SetCursor(Point mousePt);
- //see comment in Selection.h
-
- virtual Boolean Click(const EventRecord* event, TClickCommandInfo* clickCommandInfo
- , ClickLoopProcPtr clickProc = nil, void* clickProcData = nil);
-
- inline Boolean IsSelectionVisible(const Rect* visRect, LongPoint* scrollVals
- , short visOption =kCenterSelection, Boolean visSelEnd = true)
- {return fDisplay->IsSelectionVisible(visRect, scrollVals, visOption, visSelEnd);}
-
- //•Points
- inline CRunObject* Point2Char(Point thePt, TOffsetRange* charRange, Boolean* outside)
- {return fDisplay->Point2Char(thePt, charRange, outside);}
- //•returns a val < 0 in charRange->rangeStart if the point is not in any frame
-
- CRunObject* Point2Word(Point thePt, TOffsetRange* wordRange, Boolean* outside);
- /* -•returns a val < 0 in wordRange->rangeStart if the point is not in any frame
- -thePt is in local coord
- -the returned result has the same meaning as in Point2Char
- -wordRange->rangeStart is set to wordRange->rangeEnd if no words at that point
- */
-
- inline long Point2Line(Point* thePt, Boolean* outside, Boolean* vOverflow, TOffsetRange* lineRange = nil) const
- {return fDisplay->Point2Line(thePt, outside, vOverflow, lineRange);}
-
- //•Chars
- inline void Char2Point(TOffset theChar, long* top, long* trailEdge=nil, short* hite =nil)
- {fDisplay->Char2Point(theChar, top, trailEdge, hite);}
- // top and trailEdge are in abs coord
- //hite in output (if not nil) is set to the line hite of the line containing the char
-
- inline Point Char2Point(TOffset theChar, short* hite =nil)
- {return fDisplay->Char2Point(theChar, hite);}
- //returns the point in draw coord
-
- inline long Char2Line(TOffset charOffset) const
- {return fFormatter->Offset2Line(charOffset);}
-
- #ifdef txtnMultiFrames
- inline long Char2Frame(TOffset charOffset) const
- {return fFrameFormatter->Char2Frame(charOffset);}
- #endif
-
- void Char2Paragraph(long offset, TOffsetRange* paragRange);
-
- //•IO
- OSErr GetRangeIOSuite(TOffsetRange* theRange, CTextensionIOSuite* rangeIOSuite, TIOFlags flags = kIOAll);
- //the returned "theRange" should be used for "ReplaceRange". It may be different if the IOSuite contains only rulers data
-
- virtual OSErr ReplaceRange(long rangeStart, long rangeEnd, TReplaceParams* replaceParams, Boolean invisible = false);
-
- //•Runs
- virtual OSErr UpdateRangeRuns(const TOffsetRange* theRange, const TAttrObjModifier* modifier
- , Boolean invisible=false);
- //"invisible" true means no formatting or update
-
- CRunObject* GetContinuousRun();
-
- #ifdef txtnRulers
- //•Rulers
- inline CRulerObject* GetNewRulerObject() const {return fRulersRanges->GetNewRuler();}
-
- inline const CRulerObject* Offset2Ruler(TOffset charOffset) const
- {return (CRulerObject*)(fRulersRanges->Offset2Object(charOffset));}
- //Offset2Ruler returns always a valid ruler (ruler with all attributes set)
-
- OSErr UpdateRangeRulers(const TOffsetRange* theRange, const TAttrObjModifier* modifier, Boolean invisible=false);
- //"invisible" true means no formatting or update
- #endif
-
- #ifdef txtnAdvRulers
- void CopyRuler();
- void PasteRuler();
- inline Boolean CanPasteRuler() {return fClipboardRuler != nil;}
- #endif
-
- //•Apply saved data
- virtual void FreeData();
-
- #ifdef txtnNever
- //made to be called when read an already saved textension data, call FreeData, change textension data, then call CharsChanged
- OSErr CharsChanged(TCharsChangedFlags flags=kCalcAll);
-
- //•context
- void GetContext(TTextensionContext* context) const;
- void SetContext(const TTextensionContext* context);
- virtual long GetActivContextId() const;
- Boolean ActivatContext(long contextId, Boolean turnSelOn =true);
- virtual void ChangeContext(long contextId, Boolean turnSelOn =true);
- #endif
-
-
- //•Misc.
- virtual void SetDirection(char newDirection);
- inline char GetDirection() const {return fDisplay->GetDirection();}
-
- #ifdef txtnScal
- virtual void SetScale(Point numer, Point denom);
- inline void GetScale(Point* numer, Point* denom) {fDisplay->GetScale(numer, denom);}
- #endif
-
- inline void SetCRFlag(Boolean newFlag) {fFormatter->SetCRFlag(newFlag);}
- // does NOT have a draw or format effect, caller will normally call format and redraw after this
- inline Boolean GetCRFlag() const {return fFormatter->GetCRFlag();}
-
- inline long CountLines() const {return fFormatter->CountLines();}
-
- #ifdef txtnScal
- inline long GetLinesHite(long firstLine, long lastLine, Boolean scaled=true) const
- {return fFrameFormatter->GetLinesHite(firstLine, lastLine, scaled);}
-
- inline long GetTotalLinesHite(Boolean scaled = true) const
- {return fFrameFormatter->GetTotalLinesHite(scaled);}
- #else
- inline long GetLinesHite(long firstLine, long lastLine) const
- {return fFrameFormatter->GetLinesHite(firstLine, lastLine);}
-
- inline long GetTotalLinesHite() const
- {return fFrameFormatter->GetTotalLinesHite();}
- #endif
-
- protected:
- //----------
- CTextensionDisplay* fDisplay;
-
- CSelection* fSelection;
-
- CFormatter* fFormatter;
- CFrameFormatter* fFrameFormatter;
-
- #ifdef txtnRulers
- CRulersRanges* fRulersRanges;
- #endif
-
- virtual CRunObject* UpdatePendingRun();
-
- #ifdef txtnNever
- virtual OSErr NewRunsInstalled(long offset, long len, Boolean invisible = false);
- //"invisible" true means no formatting or update
- #endif
-
- virtual void BeginEdit(TEditInfo* editInfo);
- virtual void EndEdit(const TEditInfo* editInfo, long firstFormatLine, long lastFormatLine
- , TOffset* selOffset=nil, Boolean updateKeyScript=true);
-
- private:
- //--------
- CRunObject* fPendingRun;
-
- uchar fBufferedChar;
-
- static CRunObject* fDefaultRun;
-
- #ifdef txtnAdvRulers
- static CRulerObject* fClipboardRuler;
- #endif
-
- static CTextensionScrap* fLocalScrap;
-
- //•Editing
- long ClearKeyDown(uchar key, TOffsetRange* range2Clear);
-
- OSErr UpdateFormatter(long updateFlags, const TOffsetRange* range
- , long* firstFormatLine, long* lastFormatLine);
-
- //•Runs
- CRunObject* IsRangeGraphicsObj(const TOffsetRange* charRange =nil);
-
- //•for CSelection
- void Point2Paragraph(Point thePt, TOffsetRange* paragRange, Boolean* outside);
- //•returns a val < 0 in paragRange->rangeStart if the point is not in any frame
-
- /*
- void Point2Ruler(Point thePt, TOffsetRange* rulerRange);
- //•returns a val < 0 in rulerRange->rangeStart if the point is not in any frame
- */
-
- //•Misc
- void Compact();
-
- void UpdateKeyboardScript();
-
- //•input/output
- };
- //***************************************************************************************************
-
-
- #endif
-